﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xugege.AbpExtension.Application.Extension.Statement.Dto;
using Abp.Domain.Repositories;
using Abp.Extension.JxEvent.Application.JxEvent.Statistics;
using Abp.Extension.JxEvent.Core;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;

namespace Xugege.AbpExtension.Application.Extension.Statement
{
    public class SimpleStatisticsAppService : AbpZeroTemplateAppServiceBase, ISimpleStatisticsAppService
    {
        private readonly IJxEventStatisticsAppService _jxEventStatisticsAppService;

        public SimpleStatisticsAppService(IJxEventStatisticsAppService jxEventStatisticsAppService)
        {
            _jxEventStatisticsAppService = jxEventStatisticsAppService;
        }
        /// <summary>
        /// 数字统计
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<IList<FigureStatisticOutputDto>> FigureStatistics(FigureStatisticInputDto input)
        {
            IList<FigureStatisticOutputDto> result = new List<FigureStatisticOutputDto>();

            if (input.Keys == null || input.Keys.Count == 0) throw new Exception(L("ParamError"));
            foreach (var key in input.Keys)
            {
                FigureStatisticOutputDto r = new FigureStatisticOutputDto();
                //TODO 根据key 判断数据源 获取数据
                //StatisticKeys 预定义所有的key
                if (key.Equals(StatisticKeys.JxEventFigureStatistics_Pending))
                {
                    var PendingCount = await _jxEventStatisticsAppService.PendingCount();
                    r.Value = PendingCount.Value;
                    r.Title = "待处理";
                    r.ApiKey = key;
                    r.Statu = PendingCount.Statu;
                    result.Add(r);
                   
                }
                if (key.Equals(StatisticKeys.JxEventFigureStatistics_Doing))
                {
                    var DoingCount = await _jxEventStatisticsAppService.DoingCount();
                    r.Value = DoingCount.Value;
                    r.Title = "处理中";
                    r.ApiKey = key;
                    r.Statu = DoingCount.Statu;
                    result.Add(r);                    
                }
                if (key.Equals(StatisticKeys.JxEventFigureStatistics_Received))
                {
                    var ReceivedCount = await _jxEventStatisticsAppService.ReceivedCount();
                    r.Value = ReceivedCount.Value;
                    r.Title = "已派单";
                    r.ApiKey = key;
                    r.Statu = ReceivedCount.Statu;
                    result.Add(r);
                   
                }
                if (key.Equals(StatisticKeys.JxEventFigureStatistics_Complete))
                {
                    var CompletedCount = await _jxEventStatisticsAppService.CompletedCount();
                    r.Value = CompletedCount.Value;
                    r.Title = "已完成";
                    r.ApiKey = key;
                    r.Statu = CompletedCount.Statu;
                    result.Add(r);                  
                }
                if (key.Equals(StatisticKeys.JxEventFigureStatistics_Launch))
                {
                    var LaunchCount = await _jxEventStatisticsAppService.LaunchCount();
                    r.Value = LaunchCount.Value; 
                    r.Title = "共发起";
                    r.ApiKey = key;
                    r.Statu = LaunchCount.Statu;
                    result.Add(r);
                }
            }
            return await Task.FromResult(result);
        }
    }
}
